package com.admin.action;

import com.admin.service.ServiceAdmin;
import com.uni.entity.User;
import com.uni.service.Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * --------------project-------------
 *
 * @Author Unirithe  - Mr.Chao
 * - CSDN:
 * https://blog.csdn.net/Unirithe
 * - GitHub:
 * https://github.com/unirithe
 * @create 2021/12/28 23:27
 * ------------------------------------------
 */
@WebServlet(name = "AdminUpdateUserAction", urlPatterns = "/adminUpdateUser")
public class AdminUpdateUserAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.parseInt(req.getParameter("select_name"));
        String pw = req.getParameter("pw");
        User user = Service.user.queryUserById(id).clone();
        user.setPassword(pw);
        if(ServiceAdmin.admin.updateUser(user))
            resp.getWriter().write("true");
        else
            resp.getWriter().write("false");
    }
}
